﻿<!--#Include File = "CustomTemplate.asp" -->

<%
	Call  PageController.RenderPage()
	Public Function Page_Configure()
		PageController.PageTitle = "Send request publish"
		PageController.AuthorizedRoles =  Array("writer","publisher")
		pageController.RequiresAuthentication  = True
		PageController.PageCSSFiles = "main.css" 		
	End function
%>
<%Public Function Page_RenderForm()%>
	<H2>Send request publish</H2>
	

	
	<%Page.Execute%>	
	<Span Class="Caption">Request publish<HR></Span>
	

	<%panel%>
	
	
<%End Function%>

<%  '
	
	Dim txtComment
	Dim title
	
	Dim Panel

	Dim mValidation

	Dim cmdSave	
	Dim recordID
	
		
	Public Function Page_Init()
		recordID = 0  'Init
		
		
		Set txtComment	= New_ServerTextBoxEX("txtComment",100,100)	
		
		Set cmdSave = New_ServerLinkButton("cmdSave")		
		
		Set mValidation = New ServerValidationSummary
		Set panel = New_ServerPanel("Panel",500,400)
		
	End Function

	Public Function Page_Controls_Init()		
		cmdSave.Text = "Send"		
	
		txtComment.Mode=3
		txtComment.Rows = 5
		txtComment.Cols = 40
		panel.Mode = 2
	
		panel.PanelTemplate = "RenderPanel"
	End Function

	Public Function Page_Load()	
		If Not Page.IsPostBack Then

			If Request.QueryString("id")<>"" Then
				recordID = Clng(Request.QueryString("id"))			
				 
			End if
			Call LoadRecord()
						
		End If	
	End Function
	
	Public Function Page_LoadViewState()
		recordID = Page.ViewState.GetValue("ID") 'Get from viewstate	
		

	End Function
	Public Function Page_PreRender()
		Page.ViewState.Add "ID",recordID 'Add to viewstate :-)
	
	End Function

	Public Function cmdSave_OnClick()
		Dim sSQL
		Dim rs	
		
		Call Validate()
		If Not mValidation.IsValid Then
			Exit Function
		End If		
		sSQL = "SELECT * FROM approval Where contentid=" & recordID
		'Response.Write(sSQL)
		
		Set rs = DBLayer.GetRecordSet(sSQL)
		
		
		If rs.RecordCount = 0 Then
			rs.AddNew
		End If
		
		rs("contentid").Value	= recordID
		rs("requestcomment").Value    = txtComment.Text	
		rs("userrequest").Value		= CurrentUser.UserID()
		rs("requesttime").Value		= Now()		
		rs("status").Value = 10 '10 => request publish
		DBLayer.UpdateRecordSet rs
		
		sSQL = "SELECT * FROM content Where id=" & recordID
		Set rs = DBLayer.GetRecordSet(sSQL)
		If rs.RecordCount <> 0 Then
			rs("status").Value=2 ' 2=> pending wait for approval
			DBLayer.UpdateRecordSet rs
		End If
		
		
		If mValidation.IsValid Then
			Response.Redirect "content.asp"
		End If
		
	End Function
	
	Public Function Validate()
		
		'You could use several approaches to validation. I normaly use this approach and modify the control output as appropriate
	
		'(object,strFriendlyName, intDataType, bolRequired, strDefaultValue)
		mValidation.Validate 	txtComment,"Request comment", VALIDATION_DATATYPE_STRING, True , ""
	
		
	End Function

	Public Function LoadRecord()
		Dim sSQL
		Dim rs
		
		
		sSQL = "SELECT * FROM content Where id=" & recordID
		Set rs = GetRecordSet(sSQL)
		
		If rs.RecordCount > 0 Then
			title = rs("title").Value
				
		End If
		
		
			
	End Function

	
%>


<%Function RenderPanel() %>
<%mValidation%>
	<table border=0 ID="Table1">
		<tr><td>Content </td><td><a target="_blank" href="../Default.asp?act=content&id=<%Response.Write(recordID)%>"><%Response.Write(title)%></a></td></tr>
		<tr><td>Request Comment</td><td><%txtComment%></td></tr>	
	
		<tr><td colspan=2 align=left><a href="Content.asp"><HR>Back</a> | <%cmdSave%></td></tr>
	</table>
	
<%End Function%>
